<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@page import="com.ja.domain.Data"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
	<head style="display:none;">
		<title>首页</title>
		<%@include file="/WEB-INF/base.jspf"%>
		<script type="text/javascript" src="/js/jqthumb.js"></script>
		<script src="/js/font_595888_1jlcfz62jg8vkj4i.js"></script>
		<link rel="stylesheet" href="/css/style.css" />
		<script type="text/javascript" src="/js/lotterHelper.js"></script>
		<link rel="stylesheet" type="text/css" href="/icofont/iconfont.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_577691_7wy37soka4kuik9.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_577691_crwnjaug6bwt57b9.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_618617_vkhq7ruzoi0sh5mi.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_620062_v2tw0aumk6ueg66r.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_668936_16k6ml2pzufy9zfr.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_684984_s1rwld9n9e019k9.css">
		<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_689774_1c0brtga5fzs38fr.css">
		<script src="/js/datePicker.js"></script>
		<script type="text/javascript" src="/js/Tween.min.js"></script>
		<script type="text/javascript" src="/js/iscroll.js"></script>	
		<link rel="stylesheet" href="/css/animate.min.css">
		<script src="/js/font_595888_1jlcfz62jg8vkj4i.js"></script>
		<script src="//at.alicdn.com/t/font_621086_w750avfudnc7syvi.js"></script>
		<script src="/js/clipboard.min.js"></script>
		<link rel="stylesheet" href="/css/font_621086_w750avfudnc7syvi.css">
		<link rel="stylesheet" href="/kindeditor/themes/default/default.css" />
		<script src="https://at.alicdn.com/t/font_577691_1lsr8upd5qshh0k9.js"></script>
		<script src="https://at.alicdn.com/t/font_577691_cbd5g1lsegzdj9k9.js"></script> 
		 <script src="/js/common.js"></script>
		 <link rel="stylesheet" type="text/css" href="/css/reset.css"/> 
		<script type="text/javascript" src="/js/howler.min.js"></script>
		<script type="text/javascript" src="/js/bjlHelper.js"></script>
		<script type="text/javascript" src="/js/zhengzeTools.js"></script>
			<style type="text/css">
			.layui-layer-page .layui-layer-content {padding: 10px;}
		</style>
	</head>
	<body>
	<div id="loading" class="kd-loading">
		<div class="kd-spinner">
			<span class="bounce b1"></span>
			<span class="bounce b2"></span>
			<span class="bounce b3"></span>
		</div>
		<p>&nbsp;</p>
		<p>&nbsp;</p>
		<p>请稍等，努力加载中...</p>
	</div>
	<div id="xfm" style="display: none;">
		
	</div>
	
	<div class='col-xs-12 col-sm-4 col-sm-offset-4 foot dhssdhgbsdfg' style="position:flexd;background: #059BF3;display: none;">
		<a class="sy active">
			<span class="glyphicon glyphicon-th-large" style="padding-left: 2px;"></span>
			<div class="title">首页</div>
		</a><a class="gc">
			<span class="glyphicon glyphicon-list-alt" style="padding-right: 3px;"></span>
			<div class="title">购彩</div>
		</a><a class="kj">
			<span class="glyphicon glyphicon-tower"></span>
			<div class="title">开奖</div>
		</a><a class="zs">
			<span class="glyphicon glyphicon-random"></span>
			<div class="title">走势</div>
		</a><a class="wd">
			<span class="glyphicon glyphicon-user"></span>
			<div class="title">我的</div>
		</a>
	</div>
	<script type="text/javascript">
	var allLotter=["bjpk10","2fpk10","xyft","2fft","xysm","2fssc","cqssc","tjssc","cqkl10f","gdkl10f","ah11x5","gd11x5","jx11x5","sd11x5","sh11x5","pl3","shssl","ahk3","fc3d","gxk3","jsk3","3fk3","2fk3","bjk3","5f6hc","xg6hc","bj28","xy28","jnd28","bjl"]
	var page=""   //当前页
	var windowChange=true;
	/* var userState */
	var caizhong_cname=""
	var lotterName
	var timer
	var isLoad=false;
	var daojishi2
	var isTrue=true
	var reconnects
	var once = true;
	var indexNotice=0;  /* 0开启公告弹窗 1关闭 */
	var lotterFlag=[]  /* 用来存住禁用启用的数组，  禁用就添加进来，启用就删除该项 */
	 /* 当断开连接的时候重连服务器   */
	var rews = null; 
	var falses = true
	var whstate = false
	var	chatFlag   /* 0为关闭，1为开启 */
	var bjlFlag;  /* 0为禁用，1为开启 */
	var pageState=0   //默认没有页面更新
	var AllPage=[];//前端所有页面标志
 	page="sy"
 	var statu=""  //判断是否登录   0未登录  1用户登录或者内部登录  2试玩登录
	var save=[]; 
	var activityId;

		//一进来先储存所有页面的状态，下次来的时候就知道数据库是否更新，如果数据库更新则对该页面进行更新操作
		$.ajax({
			url: "/updatePage.do",
			type: "post",
			data: {},
			cache: false,
            async: false,   // 太关键了，学习了，同步和异步的参数
            dataType: 'json', type: 'post',
			success: function(data) {
				var datas=data.data;
				if(data.message==0){   //公告维护
					$(".div-c-noticeContentDiv").removeClass("bounceIn").addClass("bounceOut")
					if(!whstate){
						pagePreserve()
						whstate = true;
					}
					return;
				}else{
					$(".div-c-noticeContentDiv").removeClass("bounceOut").addClass("bounceIn")
					if(whstate){
						whstate = false
					}
					pageChage(datas)
				}
			}
		});
		/* 如果没有维护 */
		if(!whstate){
			firstLoadData()
			bindSetData("sy")
		}
		
		/* 页面更新 */
		function pageChage(datas){
			for(i=0;i<datas.length;i++){
				var item=datas[i];
					var pageName="R"+item.page;
				AllPage.push(pageName)
				var values=item.value;
				/* 取每个页面的状态值 */
				var arr=localStorage.getItem(pageName)
				/* 如果该页面状态值没有存过 */
				if(arr==null || arr=="null"){
					/* 把状	态值赋值给该页面 */
					localStorage.setItem(pageName,values)
					arr=values
				}
				/* 如果状态值和上一次不一样，则进行更新操作 */
				if(arr!=values){
					localStorage.setItem(pageName,values)
						localStorage.setItem(item.page,"")
						if(allLotter.indexOf(pageName.substring(1,pageName.length))!=-1){
							 bindAllLotterData(item.page)
						}else{
							bindAllData(item.page)
						} 
					}else{
				}
			}
		}

		/* 页面维护 */
		function pagePreserve(){
			$('.kd-loading').hide();
			$(".div-c-noticeContentDiv").removeClass("bounceIn").addClass("bounceOut")
			$.ajax({
				url: "/error.do",
				type: "post",
				data: {},
				success: function(data) {
					$('#xfm').html(data.data)
					$('#xfm').show();
					/* 30秒访问一次sy.do页面 */
					var errorPage=setInterval(function(){
						$.ajax({
						url: "/xfm.do",
						type: "post",
						data: {"page":"sy"},
						success: function(data) {
							if(data!=60){
								clearInterval(errorPage)
								window.location.href="/sy.do"
							}
						},
						error: function(status) {
							error.push(page)
							console.log(error)
						}
					})
					},30000)
				},
				error: function(status) {
					error.push(page)
					console.log(error)
				}
			})
		}
	 
	
	
	

	
	//底部栏切换
 	$(".dhssdhgbsdfg a").on("click",function(){
		if(page==$(this).attr("class").split(" ")[0]){
			return;
		}else{
			if(statu==0){
			 	GotoLogin()
			 	return;
			}
			clearInterval(daojishi2)
			page=$(this).attr("class").split(" ")[0] 
			if(error.indexOf(page)!=-1){
				maintenance() 
				return;
			}
			 $(this).addClass("active").siblings().removeClass("active") 
			 bindSetData(page)   //当前页
			 $(".foot").show()
			 for(i=0;i<lotterFlag.length;i++){
				 lotterDisabled(lotterFlag[i])
			 }
		}
	}) 
		
	
		/* 页面跳转 */
		$("#xfm").on("click",".GoToPage",function(){
			var that=this;
			var pageName=$(that).attr("class").split(" ")[1]
			clearInterval(daojishi2)
			if(error.indexOf(pageName)!=-1){
				maintenance() 
				return;
			}
			if(bjlFlag==0 && pageName=="kaijiangJl" && $(that).parents("#kj").length==1){
				return;
			}
				if(statu==2){  /* 试玩账号 */
					if(pageName=="agent" || pageName=="zhuanpan" || pageName=="chongzhi" || pageName=="zhanghuLs" || pageName=="bankMessage" || pageName=="cZfanshui" || pageName=="qiandao" || pageName=="damaTj" ||
	 					pageName=="onLineJL" || pageName=="contactKF" || pageName=="chess"){   //提示试玩账号不能进入
	 					  layer.msg("请先成为正式会员！")
	 					  bindAllCloseFakeModalBtns(); 
	 				 }else{
	 					 page=$(that).attr("class").split(" ")[1]
						 save.push($(that).parents(".wapper").attr("id"));
						 if(allLotter.indexOf(page)!=-1){
							 bindsetLotterData(page)
						 }else{
							 bindSetData(page) 
						 }
						 bindAllCloseFakeModalBtns() 
	 				 }
				}else{  /* 用户登录 */
					 page=$(that).attr("class").split(" ")[1]
					 save.push($(that).parents(".wapper").attr("id"));
					 if(allLotter.indexOf(page)!=-1){
						 bindsetLotterData(page)
					 }else{
						 bindSetData(page) 
					 }
					 bindAllCloseFakeModalBtns() 
				}  
		})
	
		function removeByValue(arr, val) {   //删除数组里指定元素
			for(var i = 0; i < arr.length; i++) {
			    if(arr[i] == val) {
			     arr.splice(i, 1);
			     break;
			    }
			}
		}
		
		 bindCollapseItemEvent();
		 
		 //UC浏览器的兼容
		 if (navigator.userAgent.indexOf('UCBrowser') > -1){
			 if(isIOS()){
			  document.body.addEventListener('focusin', function(){  //软键盘弹起事件
			        $(".foot").hide()
			        if($('#chongzhi input').is(':focus')){
			        	$("#header-div").hide();
			        	$(".div-c-spanTabs").hide();
			        }else{
			        	$("#header-div").show();
			        	$(".div-c-spanTabs").show();
			        }
			 
			        if($('.wapper').attr('id')=='zs'){
			        	$(".foot").show()
			        }
			        
			        if($('.wapper').attr('id')=='zhuce' || $('.wapper').attr('id')=='tryplay'   ){
			        	 $(".foot").hide()
			        }
			 }) 
			 
	 	 	 document.body.addEventListener('focusout', function(){ //软键盘关闭事件
	 			
	 				 if($('.wapper').attr('id')=='onLineJL' || $('.wapper').attr('id')=='contactKF' || $('.wapper').attr('id')=='chongzhi' || $('.wapper').attr('id')=='chongzhi' || $('.wapper').attr('id')=='kaijiangJl'
	 		        	|| $('#id-ul-xiaLaMenu').length==1 || $('.wapper').attr('id')=='dailiCommission' || $('.wapper').attr('id')=='userManage' || $('.wapper').attr('id')=='zhuanpan' || $('.wapper').attr('id')=='yHactivity' || $('.wapper').attr('id')=='yHactivityDetail')   {
	 		        	$(".foot").hide()
	 		        }else{
	 		        	$(".foot").show()
	 		        }
	 		
	 				 if($('.wapper').attr('id')=='chongzhi'){
	 					$("#header-div").show();
	 		        	$(".div-c-spanTabs").show();
	 				} 	
	 				 
	 				 if($('.wapper').attr('id')=='zs'){
	 			        	$(".foot").show()
	 			        } 
				  })  
			 }
		 }else{
		 //全浏览器的兼容
		   if($('.wapper').attr('id')=='zhuce' || $('.wapper').attr('id')=='tryplay' || $('.wapper').attr('id')=='login'){
			 document.body.addEventListener('focusin', function(){  //软键盘弹起事件
			        	 $(".foot").hide()
			 })
			document.body.addEventListener('focusout', function(){ //软键盘关闭事件
	        	 $(".foot").show()
			}) 
			} 
		 } 
		 bindAllCloseFakeModalBtns()
		
	 /* 连接websocket的方法 */
	function reconnect(){
		 var href=window.location.href;
		 var durl=/https?:\/\/([^\/]+)\//i; 
		 var domain = href.match(durl); 
  		 var url=domain[0].replace("http","ws") 
  		 rews = new WebSocket(url+"/websocket/socketServer.do");  
 		/* 连接发生错误的回调方法   */
 	 	rews.onerror = function() {  
  			/*  var url=domain[0].replace("http","ws")
  			 rews = new WebSocket(url+"websocket/socketServer.do");   */
 			 /* 连接发生错误的回调方法   */
 	 		//rews.onerror = function() {  
 				console.log("建立连接的时候发生异常错误")
 			//}
 		};  
 		
   /* 接收到消息的回调方法   */
 	rews.onmessage = function(event) {
 		var data=event.data
 		var newData=JSON.parse(data)
 		var Datas=newData.data;
 		/* 更新页面 */
 		if(newData.type==0){
 			for(i=0;i<newData.data.length;i++){
 				var item=newData.data[i];
 				localStorage.setItem("R"+item.page,item.value)
 				var pages=item.page
 				localStorage.setItem(pages,"")
 				if(allLotter.indexOf(pages)!=-1){
 					bindAllLotterData(pages) 
 				}else{
 					bindAllData(pages)
 				}
 			}
 		}
 		
 		/*聊天室开关 */
 		if(newData.type==2){
 			/* 禁用 */
 			if(newData.data==0){   /* 关闭 */
 				chatFlag=0;
 				if($("#onLineJL").length==1){
 					layer.alert("聊天室已关闭，即将返回首页");
 					setTimeout(function(){layer.closeAll();bindSetData("sy");},2000);
 				}
 			}else if(newData.data==1){  /* 开启 */
 				chatFlag=1;
 			}
 		}
 		
 		
 		/* 彩种开关发生了变化 */
 		if(newData.type==3){
 			/* 禁用 */
 			if(newData.data.state==0){
 				lotterFlag.push(Datas.cname);
 				lotterDisabled(Datas.cname)
 			}else if(Datas.state==1){  /* 启用 */
 				removeByValue(lotterFlag,Datas.cname)
 				lotterEnabled(Datas.cname)
 			}
 		}
 		
 		if(newData.type==4){ /* 用户被后台管理员禁用 */
 			clearInterval(reconnects);
 			once = true;//当清除定时器以后把状态改成true
 			rews.close();
 			BackLogin("提示","亲,怀疑您的账号存在风险,为您开启了保护")
 		}
 		
 		if(newData.type==5){ /* 用户密码已修改 从新登录 */
 			clearInterval(reconnects);
 			once = true;//当清除定时器以后把状态改成true
 			rews.close();
 			BackLogin("提示","亲,密码已被修改，请重新登录")
 		}
 		
 		if(newData.type==6){ /* 会员被强制下线 */
 			clearInterval(reconnects);
 			once = true;//当清除定时器以后把状态改成true
 			rews.close();
 			BackLogin("提示","亲,请谨慎操作,此账号已被强制下线")
 		}
 		
 		if(newData.type==7){ /* 账号在另外一个地方登陆，被强制下线 */
 			clearInterval(reconnects);
 			once = true;//当清除定时器以后把状态改成true
 			rews.close();
 			BackLogin("提示","亲,您的账号已在另外一个地点登陆，已被强制下线")
 		}
 		
 		if(newData.type==8){ /* 用户自己改了密码被强制下线 重新登录 */
 			clearInterval(reconnects);
 			once = true;//当清除定时器以后把状态改成true
 			rews.close();
 			BackLogin("提示","亲,恭喜您修改密码成功,请重新登录")
 		}
 	};

 	/* 连接成功建立的回调方法 */
	 rews.onopen = function(event){
			console.log("建立连接成功");
	};
       
 	/* 连接关闭的回调方法   */
 	rews.onclose = function(event) {
 		/* setMessageInnerHTML("k45jk459fgjdf986kjh98fgdkj3i45y89fdh4598hp90u断开连接，对方将不再收到你的消息"); */  
 		console.log("关闭连接")
 	};  
 	/* 监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。   */
 	window.onbeforeunload = function() { 
 		rews.close();  
 	}; 
 	/* 每十秒判断一下后台有没有断开 */
 	if(once){
 		once = false;
		reconnects=setInterval(function(){
			/* 后台断开了就重连 */
			console.log("我在调用reconnect()方法")
			if(rews.readyState != 1){
				reconnect();
			}
	  },30000)
 	}
 }
		 
			/* 强制下线的方法 */
		 	function BackLogin(title,content){
		 		layer.open({
					    type: 1,
					    area:['240px',"150px"],
					    title:title,
					    shadeClose: false, //点击遮罩关闭
					    anim: 5,
					    content:content,    //右边也可以自己定义样式，引用时最外面的那个id,如$("#"+"ID名")
					    btn:'知道了',
			 			yes:function(layero,index){
			 				layer.closeAll()
			 				bindSetData("login");
			 		    }
				}); 
		 	};
  
		  
	function lotterDisabled(cname){  /* 该彩种禁用 */
		if(cname=="bjl"){
			bjlFlag=0;
		}
		if($("#sy").length==1){
			 $('#sy #rmcz').find('.'+cname).addClass('gray');
			 $('#sy #rmcz').find('.'+cname).find('img').attr("src","/img/caizhong/gray_"+cname+".png");
		}else if($("#gc").length==1){
			$('#gc #cai').find('.'+cname).addClass('gray');
			$('#gc #cai').find('.'+cname).find('img').attr("src","/img/caizhong/gray_"+cname+".png");
		}else if($("#kj").length==1){
			$('#kj #cai').find('.'+cname).addClass('gray');
			$('#kj #cai').find('.'+cname).find('img').attr("src","/img/caizhong/gray_"+cname+".png");
		}
	}; 
	
	function lotterEnabled(cname){  /* 该彩种启用 */
		if(cname=="bjl"){
			bjlFlag=1;
		}
		 if($("#sy").length==1){
			 $('#sy #rmcz').find('.'+cname).removeClass('gray');
			 $('#sy #rmcz').find('.'+cname).find('img').attr("src","/img/caizhong/"+cname+".png");
		}else if($("#gc").length==1){
			$('#gc #cai').find('.'+cname).removeClass('gray');
			$('#gc #cai').find('.'+cname).find('img').attr("src","/img/caizhong/"+cname+".png");
		}else if($("#kj").length==1){
			$('#kj #cai').find('.'+cname).removeClass('gray');
			$('#kj #cai').find('.'+cname).find('img').attr("src","/img/caizhong/"+cname+".png");
		}
	};  
	
	</script>
</html>
